using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Formboard
{

    public class crossPics:PictureBox
    {
        public Image mouseOver;
        public Image mouseClickedW;
        public Image mouseClickedB;
        bool pawnInPlace;
        int row, column;
        public crossPics(int ro, int col)
        {
            row = ro;
            column = col;
            mouseOver = Properties.Resources.over;
            mouseClickedW = Properties.Resources.wstone;
            mouseClickedB = Properties.Resources.bstone;
            this.Image = null;
            this.Size = new Size(50, 50);
            int posx = 66 + col * 52;
            int posy = 68 + ro * 52;
            this.Location = new Point(posx, posy);
            this.BackColor = System.Drawing.Color.Transparent;
            pawnInPlace = false;
        }

        protected override void OnMouseEnter(System.EventArgs e)
        {
            if (!pawnInPlace)
                this.Image = mouseOver;
        }

        protected override void OnMouseLeave(System.EventArgs e)
        {
            if (!pawnInPlace)
                this.Image = null ;
        }

        protected override void OnClick(System.EventArgs e)
        { 
            if (((UserControlBoard)this.Parent).myturn)
            {
                ((UserControlBoard)this.Parent).myturn = false;
                ((UserControlBoard)this.Parent).lastSeqNumber++;
                CalculMove currentMove = new CalculMove(((UserControlBoard)this.Parent).goban, ((UserControlBoard)this.Parent).myColor, row + 1, column + 1);
                if (currentMove.moveResult == 0)    //move has been locally validated
                {
                    ((UserControlBoard)this.Parent).myturn = false;
                    ((UserControlBoard)this.Parent).TellGrandFatherToSendAMove(row, column);
                    ((UserControlBoard)this.Parent).TellGrandFatherToUpdateHistory(((UserControlBoard)this.Parent).lastSeqNumber, ((UserControlBoard)this.Parent).myColor, row + 1, column + 1);
                    ((UserControlBoard)this.Parent).update_graphic_board();
                }
                else
                {
                    ((UserControlBoard)this.Parent).myturn = true;
                    ((UserControlBoard)this.Parent).lastSeqNumber--;
                }
            }
        }

        public void updateCell(EnumCell status)
        {
            switch (status)
            {
                case EnumCell.Free:
                    this.Image = null;
                    pawnInPlace = false;
                    break;
                case EnumCell.White:
                    this.Image = mouseClickedW;
                    pawnInPlace = true;
                    break;
                case EnumCell.Black:
                    this.Image = mouseClickedB;
                    pawnInPlace = true;
                    break;
                default:
                    break;
            }
        }

    }
}
